//
//  WBWelcomeController.m
//  sinaWeibo
//
//  Created by 李江波 on 2016/11/16.
//  Copyright © 2016年 lijiangbo. All rights reserved.
//

#import "WBWelcomeController.h"
#import <Masonry.h>
#import <UIImageView+WebCache.h>
#import "WBOAuthViewModel.h"
#import "WBUserInfoModel.h"

#import "WBTabController.h"

#define margin 120

@interface WBWelcomeController ()

@property(nonatomic ,weak) UIImageView *icon;
@property(nonatomic ,weak) UILabel *lbl;

@end

@implementation WBWelcomeController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self setupUI];
    
}

-(void)viewDidAppear:(BOOL)animated{

    [super viewDidAppear:animated];
    
    [self setAnimation];
}


/**
 设置动画
 */
-(void)setAnimation{

    CGFloat newDistance = -(kUISCRRENH - margin - _icon.bounds.size.height);
    
    [UIView animateWithDuration:1.5 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:7 options:UIViewAnimationOptionCurveEaseIn animations:^{
        
        [_icon mas_updateConstraints:^(MASConstraintMaker *make) {
           
            make.bottom.equalTo(self.view).offset(newDistance);
            
        }];
        
        [self.view layoutIfNeeded];
        
        
    } completion:^(BOOL finished) {
        
        [UIView animateWithDuration:1 animations:^{
            
            _lbl.alpha = 1;
            
        } completion:^(BOOL finished) {
            
            [[NSNotificationCenter defaultCenter] postNotificationName:kChangeRootVc object:NSStringFromClass([WBTabController class])];
            
        }];
        
        
    }];
    
}

-(void)setupUI{

    UIImageView *icon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"avatar_default_big"]];
    
    UILabel *title = [UILabel cz_labelWithText:@"欢迎归来😯" fontSize:16 color:[UIColor purpleColor]];
    
    icon.layer.cornerRadius = 42.5;
    icon.layer.masksToBounds = YES;
    
    NSString *iconStr = [WBOAuthViewModel shared].userModel.avatar_large;
    [icon sd_setImageWithURL:[NSURL URLWithString:iconStr]];
    
    title.alpha = 0;
    
    _icon = icon;
    _lbl = title;
    
    [self.view addSubview:icon];
    [self.view addSubview:title];
    
    [icon mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerX.equalTo(self.view);
        make.bottom.equalTo(self.view).offset(-margin);
        make.size.mas_equalTo(CGSizeMake(85, 85));
    }];
    
    [title mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerX.equalTo(icon);
        make.top.equalTo(icon.mas_bottom).offset(50);
    }];
    
}


@end
